package com.briup.mt.service.impl;

import com.briup.mt.bean.Dataset;
import com.briup.mt.bean.DatasetExample;
import com.briup.mt.dao.DatasetMapper;
import com.briup.mt.service.IDatasetService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DatasetServiceImpl implements IDatasetService {
    @Resource
    private DatasetMapper datasetMapper;

    @Override
    public List<Dataset> query(String name) {
        DatasetExample example=new DatasetExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%"+name+"%");
        }

        List<Dataset>list=datasetMapper.selectByExample(example);
        return list;
    }

    @Override
    public void saveOrUpdate(Dataset dataset) {
        if (dataset.getId()==null){
            datasetMapper.insert(dataset);
        }else {
            datasetMapper.updateByPrimaryKey(dataset);
        }
    }
    @Override
    public void deleteById(long id) { datasetMapper.deleteByPrimaryKey(id); }
}
